<template>
  <div>
    <div class="loading-wrapper" v-if="!isLoading">
      <div class="loading"></div>
      <div class="loading-txt">正在加载中</div>
    </div>
    <div class="container" v-show="isLoading">
       <div id="slider">
        <swiper :options="swiperOption">
          <swiper-slide><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1492620937028&di=e349de63a85a8d91b1ea0dcc0040f69b&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F0%2F569c724f6c3dd.jpg" class="banner-item"  alt=""></swiper-slide>
          <swiper-slide><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1492621022681&di=b4d1bcb860d8a84738db728c4351f4d0&imgtype=0&src=http%3A%2F%2Fattachments.gfan.com%2Fforum%2F201503%2F21%2F201725bncoyueoll7b8wkl.jpg" class="banner-item"  alt=""></swiper-slide>
          <swiper-slide><img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1492621101524&di=72e46fea8f4cbc4f445088c84f293dda&imgtype=0&src=http%3A%2F%2Ftupian.enterdesk.com%2F2014%2Flxy%2F2014%2F12%2F30%2F6.jpg" class="banner-item"  alt=""></swiper-slide>
          <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
      </div>

      <div class="wrapper">
        <div class="g-title song-list">推荐歌单<router-link :to="{path: '/index/song-list'}">更多&gt;</router-link></div>
          <mu-flexbox wrap="wrap" justify="space-around" class="box" :gutter="0">
            <mu-flexbox-item basis="28%" class="item" :key="item.id" v-for="item in playList">
              <router-link :to="{name: 'listDetail',params: { id: item.dId }}">
                <div class="bar">{{item.play | formatCount}}</div>
                <img class="item-img img-response" :src="'http://hongtaofans.cn/music/resources/pic/disk/'+ item.pic" lazy="loading">
                <div class="item-name">{{item.dName}}</div>
              </router-link>
            </mu-flexbox-item>
          </mu-flexbox>
        </div>
      </div>
      <div class="footer">
        Copyright © 2016-2017  All Rights Reserved.ShawLi And HongTao_Fans
      </div>
    </div>
</template>

<script>

import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
  name: 'rage',
  data () {
    return {
      isLoading: true,
      playList: [],
      swiperOption: {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        autoplay: 2000
      }
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  created () {
    this.get()
  },
  methods: {
    get () {
      this.$http.get('http://hongtaofans.cn/music/disk/getalldisk').then((res) => {
        if (res.data.status === 1) {
          const list = res.data.result
          this.playList = list
          this.isloading = false
        }
      })
    }
  },
  filters: {
    formatCount (v) {
      if (v < 9999) {
        return v
      } else {
        return (v / 10000).toFixed(0) + '万'
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .container {
    margin-top: 112px;
  }
  .img-response {
    max-width: 100%;
    height: auto;
  }
  
  .loading {
    position: absolute;
    top: 47%;
    left: 50%;
    background: #fff;
    width: 2.5rem;
    height: 2.5rem;
    transform: translateY(-50%);
    margin-left: -1.25rem;
    background: url('../../static/rage_loading.png') no-repeat;
    background-size: cover
  }
  .loading-txt {
    position: absolute;
    top: 55%;
    color: #4a4a4a;
    transform: translateY(-50%);
    width: 100%;
    text-align: center;
  }

  .banner-item {
    width: 100%;
    background: url('../../static/banner-item-load.png') no-repeat;
    background-size: cover;
  }

  .wrapper {
    padding: 0 5px 0 8px ;
  }

  .g-title {
    padding-left: 25px;
    color: #333;
    height: 35px;
    line-height: 35px;
    font-size: 16px;
    background: url("../../static/aei.png") no-repeat left center;
    background-size: 20px 20px;
    a {
      float: right;
      font-size: 14px;
    }
  }

   .item {
    position: relative;
    margin: 0 5px 0px 10px;
    height: 100%;
    a {
      color: rgba(0, 0, 0, 0.87);
    }
    .bar {
      position: absolute;
      top: 0;
      left: 0;
      color: #fff;
      width: 100%;
      text-align: right;
      padding: 2px 5px;
      background-color: rgba(0,0,0,.2);
    }

    &-img {
      min-width:5rem;
      min-height: 5rem;
    }

    &-img[lazy=loading] {
      background: url('../../static/default_cover.png') no-repeat;
      background-size: cover;
    }

    &-name {
      overflow: hidden;
      font-size: 14px;
      height: 1.7rem;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }

  .footer {
    text-align: center;
    font-size: 0.3rem;
    color: #8e8e8e;
    padding:17px 0;
    background-color: #eee;

  }
</style>
